﻿using System.Drawing.Imaging;
using System.Web;
using System.Web.SessionState;
using Meotom.Upload.v2.Data.Utilities;

namespace Meotom.Upload.v2.Services
{
    /// <summary>
    /// Summary description for Capcha
    /// </summary>
    public class Capcha : IHttpHandler, IRequiresSessionState
    {
        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "image/jpeg";
            var strImageText = context.Session["CaptchaImageText"];
            if (strImageText == null) return;
            var ci = new CaptchaImage(strImageText.ToString(), 98, 29, "Microsoft Sans Serif",
                                      System.Drawing.Color.FromArgb(0, 0, 0),
                                      System.Drawing.Color.FromArgb(255, 255, 255));
            context.Response.Clear();
            ci.Image.Save(context.Response.OutputStream, ImageFormat.Jpeg);
            ci.Dispose();
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}